﻿using IDogRepository;
using Microsoft.Extensions.Logging;
using SqlSugar;

namespace DogRepository
{
    public class BaseRepository<T> : IBaseRepository<T> where T : class, new()
    {
        protected readonly ISqlSugarClient _base;
        protected readonly ILogger<BaseRepository<T>> Nlog;

        public BaseRepository(ISqlSugarClient sqlSugarClient, ILogger<BaseRepository<T>> logger)
        {
            _base = sqlSugarClient;
            Nlog = logger;
        }

        public bool Creat(T t)
        {
            //Nlog.LogInformation("执行了BaseRepository里的Create方法");
            return _base.Insertable(t).ExecuteCommand() > 0 ? true : false;
        }

        public List<T> GetAll()
        {
            //Nlog.LogInformation("执行了BaseRepository里的GetAll方法(获取所有的数据)");
            return _base.Queryable<T>().ToList();
        }
    }
}